package com.java1412.goods.controller;

import com.java1412.common.entity.Goods;
import com.java1412.goods.service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author java1412
 * @since 2025-05-13 15:37
 */
@RestController
@RequestMapping(value = "/api/v1/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @GetMapping(value = "/findByGoodsId")
    public Object findByGoodsId(@RequestParam(value = "goodsId") Integer goodsId) {
        Goods goods = goodsService.findById(goodsId);
        return goods;
    }

    @GetMapping("/findClusterName")
    public Object findClusterName(HttpServletRequest request) {
        // 获取是哪个节点被请求
        String clusterName = "当前服务器名称:" + request.getServerName()
                + ",当前集群节点的端口号:" + request.getServerPort();
        return clusterName;
    }
}
